/*
* @Description:全局数据
*/
'use strict'
import cookie from "js-cookie";
import store from "@/store";
export default {
namespaced: true,
state: {
userInfo: window.localStorage.getItem('userInfo') ? JSON.parse(window.localStorage.getItem('userInfo')) : {},
roles: window.localStorage.getItem('roles') ? JSON.parse(window.localStorage.getItem('roles')) : [],
},
actions: {
/**
* @description 设置state
* @param {Object} payload 参数名称 {String} state
* @param data {Object} 参数
* @param data.key {String} key
* @param data.value {String} value
*/
setData({state}, data) {
const keys = Object.keys(state)
let indexKey = data.key.split('.')[0]
if (!keys.includes(indexKey)) return console.error('不要输入不存在的值')
state[data.key] = data.value
},
setUserInfo({state}, data) {
state.userInfo = data
state.roles = data.角色信息
window.localStorage.setItem('userInfo', JSON.stringify(data))
window.localStorage.setItem('roles', JSON.stringify(data.角色信息))
},
logout({commit, state, dispatch}) {
return new Promise((resolve, reject) => {
cookie.remove("TOKEN");
window.localStorage.clear();
resolve();
});
},
},
}